package com.rising.face.thread.yield;

public class YieldMainTest {
    public static void main(String[] args) {
        Thread threada = new Thread(new Runnable() {
            @Override
            public void run() {
                int i = 0;
                while (i < 20) {
                    if (i == 5) {
                        Thread.yield();
                        System.out.println("----------线程A让步");
                    }
                    System.out.println("线程A--》" + i);
                    i++;
                }
            }
        }, "A");
        Thread threadb = new Thread(new Runnable() {
            @Override
            public void run() {
                int i = 0;
                while (i < 20) {
                    if (i == 10) {
                        Thread.yield();
                        System.out.println("----------线程B让步");
                    }
                    System.out.println("线程B--》" + i);
                    i++;
                }
            }
        }, "B");
        threada.start();
        threadb.start();
    }
}
